<?php
/**
 * Controller is the customized base controller class.
 * All controller classes for this application should extend from this base class.
 */
class BaseController extends CController
{
    public $pageTitle;
    public $pageKeywords;
    public $pageDescription;
    /**
     * @var string the default layout for the controller view. Defaults to '//layouts/column1',
     * meaning using a single column layout. See 'protected/views/layouts/column1.php'.
     */
    /**
     * @var array context menu items. This property will be assigned to {@link CMenu::items}.
     */
    public $menu=array();
    /**
     * @var array the breadcrumbs of the current page. The value of this property will
     * be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
     * for more details on how to specify this property.
     */
    public $breadcrumbs=array();

    /**
     * @var string Must be setted by child classes
     */
    protected $authFrom = '';

    /**
     * Filters
     * @return array
     */
    public function filters()
    {
        return array(
            'AuthControl', // more complicated auth checks to detect unauthorized access
        );
    }

    /**
     * This filter is checking unauthorized access of logged in user (ex. User that was successfully
     * authenticated on frontend goes to backend - he will be logged out)
     * Checks authFrom flag from auth cookie
     * @param  $filterChain CFilterChain
     * @return void
     */
    public function filterAuthControl($filterChain)
    {
        if (!Yii::app()->user->isGuest && Yii::app()->user->authFrom != $this->authFrom)
        {
            Yii::app()->user->logout();
            $this->redirect(Yii::app()->homeUrl);
        }
        $filterChain->run();
    }
}